package com.woniuxy.yygh.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.yygh.common.result.Result;
import com.woniuxy.yygh.enums.OrderStatusEnum;
import com.woniuxy.yygh.model.order.OrderInfo;
import com.woniuxy.yygh.order.service.OrderService;
import com.woniuxy.yygh.vo.order.OrderQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 后台订单管理
 * <P> Date: 2022/3/6:19:56
 * <P> Description:
 */
@RestController
@RequestMapping("/admin/order/orderInfo")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
        * TODO:获得所有的订单
    **/
    @GetMapping("/findAllOrder/{page}/{limit}")
    public Result findAllOrder(@PathVariable Long page,
                               @PathVariable Long limit,
                               OrderQueryVo orderQueryVo){

        Page<OrderInfo> pageParam = new Page<>(page, limit);
        IPage<OrderInfo> pageModel = orderService.selectPage(pageParam, orderQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * TODO:获取所有订单的状态
     **/
    @ApiOperation(value = "获取订单状态")
    @GetMapping("/getStatusList")
    public Result getStatusList() {
        return Result.ok(OrderStatusEnum.getStatusList());
    }

    /**
     * TODO:根据订单取消预约
     **/
    @GetMapping("/cancelOrder/{orderId}")
    public Result cancelOrder(@PathVariable String orderId){
        boolean isCancel =  orderService.adminCancelOrder(orderId);
        return Result.ok(isCancel);
    }

    /**
     * TODO:根据订单id查询订单详情
     **/
    @GetMapping("/getOrders/{orderId}")
    public Result getOrders(@PathVariable String orderId) {
        OrderInfo orderInfo = orderService.getOrder(orderId);
        return Result.ok(orderInfo);
    }
}
